Namespace PL.CoreSDK
    Public Class Account_PL
        Inherits PLBase

        Public Shared Property aAccountRow As DataRow

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Overrides Sub ValidateRow(row As DataRow)
            row.ClearErrors()
            'Mandatory Fields
            'TODO: Cache MetaString in AppManager, so here we read it once maybe for nothing
            'Dim ms As MetaString
            'ms = MetaString.GetMetaStringByCode("Mandatory", AppManager.ApplicationOption.LanguageId)
            'If IsDBNull(row("StatusId_FK")) Then
            '    row.SetColumnError("StatusId_FK", "Mandatory")
            'End If
            'If IsDBNull(row("SocietyName")) Then
            '    row.SetColumnError("SocietyName", "Mandatory")
            'End If
            ''
            'If row.HasErrors Then
            '    row.RowError = "Please check your columns, a validation error occur"
            'End If
        End Sub

        Public Shared Function GetAccountByID(ByVal accountID As Guid) As DataRow
            If aAccountRow Is Nothing OrElse DirectCast(aAccountRow("AccountID"), Guid) <> accountID Then
                Using site As MetaQuery = MetaQuery.GetMetaQueryByName("Account")
                    site.SQLWhere = String.Format("AccountId = '{0}'", accountID.ToString) 'DefaultRecord = True
                    site.FillResultQuery()
                    If site.ResultQuery.Rows.Count > 0 Then
                        aAccountRow = site.ResultQuery.Rows(0)
                    End If
                End Using
            End If
            Return aAccountRow
        End Function
    End Class
End Namespace
